﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using VideoCache.Server.BLL;
using VideoCache.Server.Model;

namespace VideoCache.Server.MVCWeb.Areas.Admin.Models
{
    public class EpisodeModel
    {
        [Display(Name = "编号")]
        public int Id { get; set; }

        [Display(Name = "专辑编号")]
        [Required(ErrorMessage = "请输入专辑编号。")]
        public int AlbumId { get; set; }

        [Display(Name = "站点编号")]
        [Required(ErrorMessage = "请选择站点。")]
        public int SiteId { get; set; }

        [Display(Name = "剧集序号")]
        [Required(ErrorMessage = "请输入剧集序号")]
        [Range(typeof(int), "1", "9999")]
        public int EpisodeIndex { get; set; }

        [Display(Name = "剧集名称")]
        public string Name { get; set; }

        [Display(Name = "剧集标记")]
        public string Token { get; set; }

        [Display(Name = "网址")]
        [Required(ErrorMessage = "请输入网址")]
        [RegularExpression("[a-zA-z]+://[^\\s]*", ErrorMessage = "请输入正确的网址")]
        public string Url { get; set; }

        [Display(Name = "允许下载")]
        public bool AllowDownload { get; set; }

        public EpisodeModel(int id)
        {
            EpisodeInfo info = EpisodeBLL.Find(id);

            if (info == null) throw new ArgumentException("指定的剧集编号不存在。");

            this.Id = info.Id;
            this.AlbumId = info.AlbumId;
            this.SiteId = info.SiteId;
            this.Name = info.Name;
            this.EpisodeIndex = info.EpisodeIndex;
            this.Token = info.Token;
            this.Url = info.Url;
            this.AllowDownload = info.AllowDownload;
        }
    }
}